<template>
	<view>
		<view v-if="list.length" class="" style="background: #f1f1f1;display:;">
			<view class="u-margin-bottom-20 list" v-for="(item,index) in list" :key="index" @click="goDetail(item)">
				<view class="u-border-bottom  u-padding-bottom-20 u-flex u-row-between">
					<view class="   $u-type-info">
						订单ID：{{item.outTradeNo}}
					</view>
					<!-- <view style="color: #3464D6;">
						{{item.cn?'普通洗车':'万能洗车'}}
					</view> -->
				</view>
				<view class="u-flex u-row-between  u-padding-top-20 u-padding-bottom-20">
					<view>{{item.storeName}}</view>
					<!-- <view>合计：<text class="$u-type-error">￥{{item.totalMoney}}</text></view> -->
					<view style="color:#666">查看详情</view>
				</view>
				<view class="u-margin-bottom-20">
					服务时间:{{item.minute}}分钟
				</view>
				<view class="u-padding-top-20 u-border-top $u-type-info">{{item.storeAddress}}</view>
				<view class="u-flex u-flex-end u-margin-top-20">
					<u-button size="mini" type="error" v-if="item.status<4" @click="end(item)">结束订单</u-button>
					<u-button size="mini" type="success" v-if="item.status>=4">已完成</u-button>
					<u-button @click="xufei(item)" size="mini" type="primary" v-if="item.status<4"
						class="u-margin-left-10">续费</u-button>
				</view>
			</view>
		</view>
		<view v-else style="text-align: center;margin-top: 150rpx;">
			<img src="/static/my_3.png" alt="" style="max-width: 48rpx;height:48rpx;">
			<view style="text-align: center;">还没有订单信息哦</view>
		</view>
		<u-toast ref="uToast" />


			<u-modal @confirm="sure" v-model="show" title="选择续费金额">
					<view class="u-padding-20 u-flex u-row-between">
						<view style="width: 30%;height: 60rpx;line-height: 60rpx;
						border-radius: 10;border: 1rpx solid #000;text-align: center;
						"
						 @click="current=index"
						  v-for="(item,index) in monenylist" :key="index"  :class="current==index?'change':''">
							￥{{item.num}}
						</view>
					</view>
					<view class="u-padding-20 u-padding-top-0">
						<u-input placeholder="请选择充值金额" border v-model="money"></u-input>
					</view>
					
			</u-modal>
	</view>


</template>

<script>
	import loader from '@/common/loadPage.js';
	import wxpay from '@/common/wxpay.js';
	export default {
		mixins: [loader],
		data() {
			return {
				info: '',
				list: [],
				initial: {
					geturl: "/indent/gameOrder",
					parm: {

					},
					isPage: true
				},
				current:0,
				show: false,
				monenylist:[{
					num:"50"
				},{
					num:"100"
				},{
					num:"200"
				}],
				money:"",
				id:""
			}

		},
		methods: {
			//续费订单金额
			sure(e){
				let selectMoney=this.monenylist[this.current].num;
				let moneys=this.money?this.money:selectMoney
				uni.showModal({
					title:"提示",
					content:"是否续费"+moneys+"元",
					success: (res) => {
						if(res.confirm){
							this.$u.post('/indent/orderRenew', {
								money:moneys ,
								id:this.id
							}).then(res => {
								if (Object.prototype.toString.call(res) == "[object Object]") {
									const wx = new wxpay(res);
									wx.pay().then(res => {
										this.$refs.uToast.show({
											title: '续费成功',
											type: 'success',
										})
									}).catch(err => {})
								} else if (Object.prototype.toString.call(res) == "[object Array]") {
									this.$refs.uToast.show({
										title: '续费成功',
										type: 'success',
									})
								}
								
								this.getGoods();
							
							}).catch(err => {})
						}
					}
				})
				
			},
			xufei(e) {
				this.show = true
				this.id=e.id
			},
			getUser() {
				this.$u.api.userInfo().then(res => {
					this.info = res;
				})
			},
			end(item) {
				this.$u.post('/indent/orderFinish', {
					order_id: item.id
				}).then(res => {
					console.log(res, "resss")
					if (!res) {
						this.$refs.uToast.show({
							title: '订单结束',
							type: 'success'
						})

					} else if (!Array.isArray(res)) {
						const wx = new wxpay(res);
						wx.pay().then(res => {
							this.$refs.uToast.show({
								title: '付款成功',
								type: 'success'
							})
						}).catch(err => {

						})
					}
					this.getGoods();

				}).catch(err => {})
			},
			goDetail(item) {
				uni.navigateTo({
					url: "/pages/my/detail?id=" + item.id
				})

				// uni.navigateTo({
				// 	url:"/pages/my/detail?id="+item.id
				// })
			},
		},
		onShow() {
			
			this.getGoods();
			this.getUser()
		}
	}
</script>

<style scoped>
	.list {
		background: #FFFFFF;
		padding: 30rpx;
	}
	.change{
		background: #629eff;
		color:#fff;
		
		
	}
</style>